package com.cf.society_management.controllers;

import com.cf.society_management.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "用户操作接口", description = "提供用户的增、删、改、查功能")
@RestController
@RequestMapping("/sm/users")
public class UserController {

    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    // 登录接口
    @PostMapping("/login")
    @ApiOperation(value = "用户登录", notes = "根据用户名和密码进行登录验证")
    public boolean login(
            @RequestParam @ApiParam(value = "用户账号", required = true) String account,
            @RequestParam @ApiParam(value = "用户密码", required = true) String password) {
        return userService.validateUser(account, password);
    }

    // 注册接口
    @PostMapping("/register")
    @ApiOperation(value = "用户注册", notes = "提供用户名、密码、邮箱等信息注册新用户")
    public boolean register(
            @RequestParam @ApiParam(value = "用户账号", required = true) String account,
            @RequestParam @ApiParam(value = "用户密码", required = true) String password,
            @RequestParam @ApiParam(value = "用户邮箱", required = true) String email,
            @RequestParam @ApiParam(value = "性别", required = true) String sexy,
            @RequestParam @ApiParam(value = "个人简介") String introduce) {
        return userService.registerUser(account, password, email, sexy, introduce);
    }
}
